<?php

class wangzhanAction extends CommonAction
{
    public function index()
    {
     /*   $taskinfo=M("tasktongji");
     //   $condition["status"]=0; //任务生效,未领取
        $condition["type"]= array("in", );
        $data=$taskinfo->where($condition)->order('id desc')->select();*/

        $projectype=$this->CacheArray("projecttype");
        $site=$this->CacheArray("site");

        $model=new Model();
        $data=$model->table('ys_task t ,ys_project p ')
            ->where('t.projectid=p.id and t.type in ('.I('session.roletasktype').')')
            ->field('t.*,p.type as ptype')
            ->order('id')
            ->select();

       //echo $model->getLastSql();exit;



        foreach($data as $k=>&$v)
        {
            $v["ttname"]=$projectype[$v["ptype"]]["name"];
            $v["domain"]=$site[$v["site"]]["domain"];

        }
//dump($data);exit();
        $this->list = $data;
        $this->display();
    }

    public function wangzhanxinxi()
    {
        $this->display();
    }

    public function woderenwu()
    {
        $task = M('task');
        $taskid = I('post.taskid');
        $data = array();
        $data['id'] = $taskid;
        $data['taker'] = I('session.userid', 0);
        $data['begintime'] = date('Y-m-d H:i:s');
        $data['status'] = "1";
        $task->save($data);

        $model = new Model();
        $name = I('post.sousuo');

        $where = "t.site=s.id and t.status>0  and t.type>11 and t.type<15 ";
        if (IS_POST || !empty($name)) {
            $where = $where . " and s.name like '%{$name}%'";
        }

        $data = $model->table('ys_task  t,ys_site s')
            ->where($where)
            ->field('t.finishtime as endtime,t.deadline ,t.name as tname,t.begintime,t.finishtime,t.status as sta,t.id as tid,s.*')
            ->order('t.status asc,t.id')
            ->select();
        $this->list = $data;
        $this->display();
    }

    public function gongzuoliang()
    {
        $this->display();
    }

    public function xiugai()
    {
        $model = M('model');
        $where = "t.site=s.id and t.projectid=p.id and p.custid=c.id and t.status=3 and p.employee=e.id";
        $data = $model->table('ys_project p,ys_customer c,ys_site s,ys_task t,ys_employee e')
            ->where($where)
            ->field('c.*,e.name as ename,t.xiugai as tnote,t.id as tid,s.domain')
            ->order('t.id desc')
            ->select();
        // echo $model->getLastSql();exit();
        $this->list = $data;
        $this->display();
    }

    public function xiugaiwan()
    {
        $task = M('task');
        $data = array();
        $data['id'] = I('post.tid');
        $data['status'] = 2;
        $count = $task->save($data);
        if ($count > 0) {
            $this->redirect("wangzhan/xiugai");
            $this->success("已完成");
        } else {
            $this->error("没有完成");
        }
    }

    public function xiugaixx()
    {
        $model = M('model');
        $where = "t.site=s.id and t.projectid=p.id and p.custid=c.id and t.status=3 and p.employee=e.id";
        $data = $model->table('ys_project p,ys_customer c,ys_site s,ys_task t,ys_employee e')
            ->where($where)
            ->field('c.*,e.name as ename,t.note as tnote,t.id as tid,s.domain')
            ->order('t.id desc')
            ->select();
        // echo $model->getLastSql();exit();
        $this->list = $data;
        $this->display();
    }

    public function wancheng()
    {
        $task = M('task');
        $taskid = I('post.taskid');
        $data = array();
        $data['id'] = $taskid;
        $data['status'] = 2;
        $data['finishtime'] = date("Y-m-d H:i:s");
        $count = $task->save($data);

        if ($count > 0) {
             $this->redirect("wangzhan/woderenwu");
            $this->success("已完成");
        } else {
            $this->error("没有完成");
        }

    }

}